<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Source code</title>
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
</head>
<body>
<main role="main">
<div class="sourceContainer">
<pre><span class="sourceLineNo">001</span><a id="line.1">/*</a>
<span class="sourceLineNo">002</span><a id="line.2"> * Licensed to the Apache Software Foundation (ASF) under one or more</a>
<span class="sourceLineNo">003</span><a id="line.3"> * contributor license agreements.  See the NOTICE file distributed with</a>
<span class="sourceLineNo">004</span><a id="line.4"> * this work for additional information regarding copyright ownership.</a>
<span class="sourceLineNo">005</span><a id="line.5"> * The ASF licenses this file to You under the Apache License, Version 2.0</a>
<span class="sourceLineNo">006</span><a id="line.6"> * (the "License"); you may not use this file except in compliance with</a>
<span class="sourceLineNo">007</span><a id="line.7"> * the License.  You may obtain a copy of the License at</a>
<span class="sourceLineNo">008</span><a id="line.8"> *</a>
<span class="sourceLineNo">009</span><a id="line.9"> *      http://www.apache.org/licenses/LICENSE-2.0</a>
<span class="sourceLineNo">010</span><a id="line.10"> *</a>
<span class="sourceLineNo">011</span><a id="line.11"> * Unless required by applicable law or agreed to in writing, software</a>
<span class="sourceLineNo">012</span><a id="line.12"> * distributed under the License is distributed on an "AS IS" BASIS,</a>
<span class="sourceLineNo">013</span><a id="line.13"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</a>
<span class="sourceLineNo">014</span><a id="line.14"> * See the License for the specific language governing permissions and</a>
<span class="sourceLineNo">015</span><a id="line.15"> * limitations under the License.</a>
<span class="sourceLineNo">016</span><a id="line.16"> */</a>
<span class="sourceLineNo">017</span><a id="line.17">package org.apache.commons.dbutils;</a>
<span class="sourceLineNo">018</span><a id="line.18"></a>
<span class="sourceLineNo">019</span><a id="line.19">/**</a>
<span class="sourceLineNo">020</span><a id="line.20"> * Configuration options for a {@link java.sql.Statement} when preparing statements in {@code QueryRunner}.</a>
<span class="sourceLineNo">021</span><a id="line.21"> */</a>
<span class="sourceLineNo">022</span><a id="line.22">public class StatementConfiguration {</a>
<span class="sourceLineNo">023</span><a id="line.23">    private final Integer fetchDirection;</a>
<span class="sourceLineNo">024</span><a id="line.24">    private final Integer fetchSize;</a>
<span class="sourceLineNo">025</span><a id="line.25">    private final Integer maxFieldSize;</a>
<span class="sourceLineNo">026</span><a id="line.26">    private final Integer maxRows;</a>
<span class="sourceLineNo">027</span><a id="line.27">    private final Integer queryTimeout;</a>
<span class="sourceLineNo">028</span><a id="line.28"></a>
<span class="sourceLineNo">029</span><a id="line.29">    /**</a>
<span class="sourceLineNo">030</span><a id="line.30">     * Constructor for {@code StatementConfiguration}.  For more flexibility, use {@link Builder}.</a>
<span class="sourceLineNo">031</span><a id="line.31">     *</a>
<span class="sourceLineNo">032</span><a id="line.32">     * @param fetchDirection The direction for fetching rows from database tables.</a>
<span class="sourceLineNo">033</span><a id="line.33">     * @param fetchSize The number of rows that should be fetched from the database when more rows are needed.</a>
<span class="sourceLineNo">034</span><a id="line.34">     * @param maxFieldSize The maximum number of bytes that can be returned for character and binary column values.</a>
<span class="sourceLineNo">035</span><a id="line.35">     * @param maxRows The maximum number of rows that a {@code ResultSet} can produce.</a>
<span class="sourceLineNo">036</span><a id="line.36">     * @param queryTimeout The number of seconds the driver will wait for execution.</a>
<span class="sourceLineNo">037</span><a id="line.37">     */</a>
<span class="sourceLineNo">038</span><a id="line.38">    public StatementConfiguration(final Integer fetchDirection, final Integer fetchSize,</a>
<span class="sourceLineNo">039</span><a id="line.39">                                  final Integer maxFieldSize, final Integer maxRows,</a>
<span class="sourceLineNo">040</span><a id="line.40">                                  final Integer queryTimeout) {</a>
<span class="sourceLineNo">041</span><a id="line.41">        this.fetchDirection = fetchDirection;</a>
<span class="sourceLineNo">042</span><a id="line.42">        this.fetchSize = fetchSize;</a>
<span class="sourceLineNo">043</span><a id="line.43">        this.maxFieldSize = maxFieldSize;</a>
<span class="sourceLineNo">044</span><a id="line.44">        this.maxRows = maxRows;</a>
<span class="sourceLineNo">045</span><a id="line.45">        this.queryTimeout = queryTimeout;</a>
<span class="sourceLineNo">046</span><a id="line.46">    }</a>
<span class="sourceLineNo">047</span><a id="line.47"></a>
<span class="sourceLineNo">048</span><a id="line.48">    /**</a>
<span class="sourceLineNo">049</span><a id="line.49">     * Get the fetch direction.</a>
<span class="sourceLineNo">050</span><a id="line.50">     *</a>
<span class="sourceLineNo">051</span><a id="line.51">     * @return The direction to fetch or null if not set.</a>
<span class="sourceLineNo">052</span><a id="line.52">     */</a>
<span class="sourceLineNo">053</span><a id="line.53">    public Integer getFetchDirection() {</a>
<span class="sourceLineNo">054</span><a id="line.54">        return fetchDirection;</a>
<span class="sourceLineNo">055</span><a id="line.55">    }</a>
<span class="sourceLineNo">056</span><a id="line.56"></a>
<span class="sourceLineNo">057</span><a id="line.57">    /**</a>
<span class="sourceLineNo">058</span><a id="line.58">     * Whether fetch direction is set.</a>
<span class="sourceLineNo">059</span><a id="line.59">     *</a>
<span class="sourceLineNo">060</span><a id="line.60">     * @return true if set, false otherwise.</a>
<span class="sourceLineNo">061</span><a id="line.61">     */</a>
<span class="sourceLineNo">062</span><a id="line.62">    public boolean isFetchDirectionSet() {</a>
<span class="sourceLineNo">063</span><a id="line.63">        return fetchDirection != null;</a>
<span class="sourceLineNo">064</span><a id="line.64">    }</a>
<span class="sourceLineNo">065</span><a id="line.65"></a>
<span class="sourceLineNo">066</span><a id="line.66">    /**</a>
<span class="sourceLineNo">067</span><a id="line.67">     * Get the fetch size.</a>
<span class="sourceLineNo">068</span><a id="line.68">     *</a>
<span class="sourceLineNo">069</span><a id="line.69">     * @return The fetch size or null if not set.</a>
<span class="sourceLineNo">070</span><a id="line.70">     */</a>
<span class="sourceLineNo">071</span><a id="line.71">    public Integer getFetchSize() {</a>
<span class="sourceLineNo">072</span><a id="line.72">        return fetchSize;</a>
<span class="sourceLineNo">073</span><a id="line.73">    }</a>
<span class="sourceLineNo">074</span><a id="line.74"></a>
<span class="sourceLineNo">075</span><a id="line.75">    /**</a>
<span class="sourceLineNo">076</span><a id="line.76">     * Whether fetch size is set.</a>
<span class="sourceLineNo">077</span><a id="line.77">     *</a>
<span class="sourceLineNo">078</span><a id="line.78">     * @return true if set, false otherwise.</a>
<span class="sourceLineNo">079</span><a id="line.79">     */</a>
<span class="sourceLineNo">080</span><a id="line.80">    public boolean isFetchSizeSet() {</a>
<span class="sourceLineNo">081</span><a id="line.81">        return fetchSize != null;</a>
<span class="sourceLineNo">082</span><a id="line.82">    }</a>
<span class="sourceLineNo">083</span><a id="line.83"></a>
<span class="sourceLineNo">084</span><a id="line.84">    /**</a>
<span class="sourceLineNo">085</span><a id="line.85">     * Get the max field size.</a>
<span class="sourceLineNo">086</span><a id="line.86">     *</a>
<span class="sourceLineNo">087</span><a id="line.87">     * @return The max field size or null if not set.</a>
<span class="sourceLineNo">088</span><a id="line.88">     */</a>
<span class="sourceLineNo">089</span><a id="line.89">    public Integer getMaxFieldSize() {</a>
<span class="sourceLineNo">090</span><a id="line.90">        return maxFieldSize;</a>
<span class="sourceLineNo">091</span><a id="line.91">    }</a>
<span class="sourceLineNo">092</span><a id="line.92"></a>
<span class="sourceLineNo">093</span><a id="line.93">    /**</a>
<span class="sourceLineNo">094</span><a id="line.94">     * Whether max field size is set.</a>
<span class="sourceLineNo">095</span><a id="line.95">     *</a>
<span class="sourceLineNo">096</span><a id="line.96">     * @return true if set, false otherwise.</a>
<span class="sourceLineNo">097</span><a id="line.97">     */</a>
<span class="sourceLineNo">098</span><a id="line.98">    public boolean isMaxFieldSizeSet() {</a>
<span class="sourceLineNo">099</span><a id="line.99">        return maxFieldSize != null;</a>
<span class="sourceLineNo">100</span><a id="line.100">    }</a>
<span class="sourceLineNo">101</span><a id="line.101"></a>
<span class="sourceLineNo">102</span><a id="line.102">    /**</a>
<span class="sourceLineNo">103</span><a id="line.103">     * Get the max rows.</a>
<span class="sourceLineNo">104</span><a id="line.104">     *</a>
<span class="sourceLineNo">105</span><a id="line.105">     * @return The max rows or null if not set.</a>
<span class="sourceLineNo">106</span><a id="line.106">     */</a>
<span class="sourceLineNo">107</span><a id="line.107">    public Integer getMaxRows() {</a>
<span class="sourceLineNo">108</span><a id="line.108">        return maxRows;</a>
<span class="sourceLineNo">109</span><a id="line.109">    }</a>
<span class="sourceLineNo">110</span><a id="line.110"></a>
<span class="sourceLineNo">111</span><a id="line.111">    /**</a>
<span class="sourceLineNo">112</span><a id="line.112">     * Whether max rows is set.</a>
<span class="sourceLineNo">113</span><a id="line.113">     *</a>
<span class="sourceLineNo">114</span><a id="line.114">     * @return true if set, false otherwise.</a>
<span class="sourceLineNo">115</span><a id="line.115">     */</a>
<span class="sourceLineNo">116</span><a id="line.116">    public boolean isMaxRowsSet() {</a>
<span class="sourceLineNo">117</span><a id="line.117">        return maxRows != null;</a>
<span class="sourceLineNo">118</span><a id="line.118">    }</a>
<span class="sourceLineNo">119</span><a id="line.119"></a>
<span class="sourceLineNo">120</span><a id="line.120">    /**</a>
<span class="sourceLineNo">121</span><a id="line.121">     * Get the query timeout.</a>
<span class="sourceLineNo">122</span><a id="line.122">     *</a>
<span class="sourceLineNo">123</span><a id="line.123">     * @return The query timeout or null if not set.</a>
<span class="sourceLineNo">124</span><a id="line.124">     */</a>
<span class="sourceLineNo">125</span><a id="line.125">    public Integer getQueryTimeout() {</a>
<span class="sourceLineNo">126</span><a id="line.126">        return queryTimeout;</a>
<span class="sourceLineNo">127</span><a id="line.127">    }</a>
<span class="sourceLineNo">128</span><a id="line.128"></a>
<span class="sourceLineNo">129</span><a id="line.129">    /**</a>
<span class="sourceLineNo">130</span><a id="line.130">     * Whether query timeout is set.</a>
<span class="sourceLineNo">131</span><a id="line.131">     *</a>
<span class="sourceLineNo">132</span><a id="line.132">     * @return true if set, false otherwise.</a>
<span class="sourceLineNo">133</span><a id="line.133">     */</a>
<span class="sourceLineNo">134</span><a id="line.134">    public boolean isQueryTimeoutSet() {</a>
<span class="sourceLineNo">135</span><a id="line.135">        return queryTimeout != null;</a>
<span class="sourceLineNo">136</span><a id="line.136">    }</a>
<span class="sourceLineNo">137</span><a id="line.137"></a>
<span class="sourceLineNo">138</span><a id="line.138">    /**</a>
<span class="sourceLineNo">139</span><a id="line.139">     * Builder class for {@code StatementConfiguration} for more flexible construction.</a>
<span class="sourceLineNo">140</span><a id="line.140">     */</a>
<span class="sourceLineNo">141</span><a id="line.141">    public static final class Builder {</a>
<span class="sourceLineNo">142</span><a id="line.142">        private Integer fetchDirection;</a>
<span class="sourceLineNo">143</span><a id="line.143">        private Integer fetchSize;</a>
<span class="sourceLineNo">144</span><a id="line.144">        private Integer maxRows;</a>
<span class="sourceLineNo">145</span><a id="line.145">        private Integer queryTimeout;</a>
<span class="sourceLineNo">146</span><a id="line.146">        private Integer maxFieldSize;</a>
<span class="sourceLineNo">147</span><a id="line.147"></a>
<span class="sourceLineNo">148</span><a id="line.148">        /**</a>
<span class="sourceLineNo">149</span><a id="line.149">         * @param fetchDirection The direction for fetching rows from database tables.</a>
<span class="sourceLineNo">150</span><a id="line.150">         * @return This builder for chaining.</a>
<span class="sourceLineNo">151</span><a id="line.151">         * @see StatementConfiguration#getFetchDirection()</a>
<span class="sourceLineNo">152</span><a id="line.152">         */</a>
<span class="sourceLineNo">153</span><a id="line.153">        public Builder fetchDirection(final Integer fetchDirection) {</a>
<span class="sourceLineNo">154</span><a id="line.154">            this.fetchDirection = fetchDirection;</a>
<span class="sourceLineNo">155</span><a id="line.155">            return this;</a>
<span class="sourceLineNo">156</span><a id="line.156">        }</a>
<span class="sourceLineNo">157</span><a id="line.157"></a>
<span class="sourceLineNo">158</span><a id="line.158">        /**</a>
<span class="sourceLineNo">159</span><a id="line.159">         * @param fetchSize The number of rows that should be fetched from the database when more rows are needed.</a>
<span class="sourceLineNo">160</span><a id="line.160">         * @return This builder for chaining.</a>
<span class="sourceLineNo">161</span><a id="line.161">         * @see StatementConfiguration#getFetchSize()</a>
<span class="sourceLineNo">162</span><a id="line.162">         */</a>
<span class="sourceLineNo">163</span><a id="line.163">        public Builder fetchSize(final Integer fetchSize) {</a>
<span class="sourceLineNo">164</span><a id="line.164">            this.fetchSize = fetchSize;</a>
<span class="sourceLineNo">165</span><a id="line.165">            return this;</a>
<span class="sourceLineNo">166</span><a id="line.166">        }</a>
<span class="sourceLineNo">167</span><a id="line.167"></a>
<span class="sourceLineNo">168</span><a id="line.168">        /**</a>
<span class="sourceLineNo">169</span><a id="line.169">         * @param maxRows The maximum number of rows that a {@code ResultSet} can produce.</a>
<span class="sourceLineNo">170</span><a id="line.170">         * @return This builder for chaining.</a>
<span class="sourceLineNo">171</span><a id="line.171">         * @see StatementConfiguration#getMaxRows()</a>
<span class="sourceLineNo">172</span><a id="line.172">         */</a>
<span class="sourceLineNo">173</span><a id="line.173">        public Builder maxRows(final Integer maxRows) {</a>
<span class="sourceLineNo">174</span><a id="line.174">            this.maxRows = maxRows;</a>
<span class="sourceLineNo">175</span><a id="line.175">            return this;</a>
<span class="sourceLineNo">176</span><a id="line.176">        }</a>
<span class="sourceLineNo">177</span><a id="line.177"></a>
<span class="sourceLineNo">178</span><a id="line.178">        /**</a>
<span class="sourceLineNo">179</span><a id="line.179">         * @param queryTimeout The number of seconds the driver will wait for execution.</a>
<span class="sourceLineNo">180</span><a id="line.180">         * @return This builder for chaining.</a>
<span class="sourceLineNo">181</span><a id="line.181">         * @see StatementConfiguration#getQueryTimeout()</a>
<span class="sourceLineNo">182</span><a id="line.182">         */</a>
<span class="sourceLineNo">183</span><a id="line.183">        public Builder queryTimeout(final Integer queryTimeout) {</a>
<span class="sourceLineNo">184</span><a id="line.184">            this.queryTimeout = queryTimeout;</a>
<span class="sourceLineNo">185</span><a id="line.185">            return this;</a>
<span class="sourceLineNo">186</span><a id="line.186">        }</a>
<span class="sourceLineNo">187</span><a id="line.187"></a>
<span class="sourceLineNo">188</span><a id="line.188">        /**</a>
<span class="sourceLineNo">189</span><a id="line.189">         * @param maxFieldSize The maximum number of bytes that can be returned for character and binary column values.</a>
<span class="sourceLineNo">190</span><a id="line.190">         * @return This builder for chaining.</a>
<span class="sourceLineNo">191</span><a id="line.191">         * @see StatementConfiguration#getMaxFieldSize()</a>
<span class="sourceLineNo">192</span><a id="line.192">         */</a>
<span class="sourceLineNo">193</span><a id="line.193">        public Builder maxFieldSize(final Integer maxFieldSize) {</a>
<span class="sourceLineNo">194</span><a id="line.194">            this.maxFieldSize = maxFieldSize;</a>
<span class="sourceLineNo">195</span><a id="line.195">            return this;</a>
<span class="sourceLineNo">196</span><a id="line.196">        }</a>
<span class="sourceLineNo">197</span><a id="line.197"></a>
<span class="sourceLineNo">198</span><a id="line.198">        /**</a>
<span class="sourceLineNo">199</span><a id="line.199">         * @return A new and configured {@link StatementConfiguration}.</a>
<span class="sourceLineNo">200</span><a id="line.200">         */</a>
<span class="sourceLineNo">201</span><a id="line.201">        public StatementConfiguration build() {</a>
<span class="sourceLineNo">202</span><a id="line.202">            return new StatementConfiguration(fetchDirection, fetchSize, maxFieldSize, maxRows, queryTimeout);</a>
<span class="sourceLineNo">203</span><a id="line.203">        }</a>
<span class="sourceLineNo">204</span><a id="line.204">    }</a>
<span class="sourceLineNo">205</span><a id="line.205">}</a>




























































</pre>
</div>
</main>
</body>
</html>
